{% extends 'rebs/layouts/base.html' %}

{% load static humanize widget_tweaks %}

{% block title %}Rebs - {% if request.GET.cont_id %}등록 계약 수정{% else %}신규 계약 등록{% endif %}{% endblock %}

{% block content %}

    <!-- Start Content-->
    <div class="container-fluid">

        <!-- start page title -->
        {% include 'rebs/partials/content_title.html' with  second_bs="분양 계약 관리" third_bs="계약 정보 관리" title="계약 등록 관리" %}
        <!-- end page title -->

        <div class="row">
            <form class="form-horizontal p-0 col-12" name="project_form" method="get">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">

                            {% with menu_order='2' %}
                                {% include 'rebs_contract/partials/head_menu.html' %}
                            {% endwith %}

                            <div class="row">
                                {% include 'rebs/partials/project_select.html' %}
                                <div class="col-sm-12 col-md-6"></div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body pb-1">
                            <div class="row">
                                {% if request.GET.cont_id %}
                                    <div class="col-12 mb-3">
                                        <!-- Button Group -->
                                        <div class="btn-group mb-3">
                                            <button type="button" class="btn btn-secondary">등록 계약 변경</button>
                                            <button type="button" class="btn btn-light" onclick="alert('준비중!')">주소(연락처) 변경</button>
                                            <button type="button" class="btn btn-light" onclick="alert('준비중!')">권리 의무 승계</button>
                                            <button type="button" class="btn btn-light"
                                                    onclick="location.href='{% url 'rebs:contract:release' %}?project={{ this_project.id }}&task={{ task }}&contractor={{ contractor.id }}{% if contractor.contractorrelease %}&release_id={{ contractor.contractorrelease.id }}{% endif %}'">
                                                계약 해지 관리
                                            </button>
                                        </div>
                                    </div>
                                {% endif %}
                                <div class="form-group mb-0 justify-content-end row col-12">
                                    <div class="col-12">
                                        <div class="form-group col-12 row">
                                            <label for="id_task"
                                                   class="col-4 col-md-2 col-lg-1 col-form-label">구분</label>
                                            <div class="col-8 col-md-4 col-lg-2">
                                                <select name="task" id="id_task" class="form-control select2"
                                                        onchange="{% if not request.GET.cont_id %}getSelect(this, 1){% else %}submit(){% endif %}">
                                                    <option value="">---------</option>
                                                    <option value="1"
                                                            {% if request.GET.task == '1' %}selected{% endif %}>청약
                                                    </option>
                                                    <option value="2"
                                                            {% if request.GET.task == '2' %}selected{% endif %}>계약
                                                    </option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group col-12 row">
                                            <label for="id_order_group" class="col-4 col-md-2 col-lg-1 col-form-label">차수</label>
                                            <div class="col-8 col-md-4 col-lg-2">
                                                <select name="order_group" id="id_order_group"
                                                        class="form-control  select2"
                                                        onchange="getSelect(this, 2)"
                                                        {% if not request.GET.task %}disabled{% endif %}>
                                                    <option value="">---------</option>
                                                    {% for obj in order_groups %}
                                                        <option value="{{ obj.id }}"
                                                                {% ifequal obj.id|stringformat:"s" request.GET.order_group %}selected{% endifequal %}>{{ obj }}</option>
                                                    {% endfor %}
                                                </select>
                                            </div>

                                            <label for="id_type"
                                                   class="col-4 col-md-2 col-lg-1 col-form-label">타입</label>
                                            <div class="col-8 col-md-4 col-lg-2">
                                                <select name="type" id="id_type" class="form-control  select2"
                                                        onchange="getSelect(this, 3)"
                                                        {% if not request.GET.order_group %}disabled{% endif %}>
                                                    <option value="">---------</option>
                                                    {% for obj in types %}
                                                        <option value="{{ obj.id }}"
                                                                {% ifequal obj.id|stringformat:"s" request.GET.type %}selected{% endifequal %}>{{ obj }}</option>
                                                    {% endfor %}
                                                </select>
                                            </div>
                                            <label for="id_contract_unit"
                                                   class="col-4 col-md-2 col-lg-1 col-form-label">계약코드</label>
                                            <div class="col-8 col-md-4 col-lg-2">
                                                <select name="contract_unit" id="id_contract_unit"
                                                        class="form-control  select2"
                                                        {% if not request.GET.type %}disabled{% endif %}
                                                        onchange="{% ifequal this_project.is_unit_set True %}getSelect(this, 3){% else %}submit(){% endifequal %}">
                                                    <option value="">---------</option>
                                                    {% for obj in contract_units %}
                                                        <option value="{{ obj.id }}"
                                                                {% ifequal obj.id|stringformat:"s" request.GET.contract_unit %}selected{% endifequal %}>{{ obj }}</option>
                                                    {% endfor %}
                                                </select>
                                            </div>

                                            {% ifequal this_project.is_unit_set True %}
                                                <label for="id_unit_number"
                                                       class="col-4 col-md-2 col-lg-1 col-form-label">동호수</label>
                                                <div class="col-8 col-md-4 col-lg-2">
                                                    <select name="unit_number" id="id_unit_number"
                                                            class="form-control  select2"
                                                            onchange="submit()"
                                                            {% if not request.GET.contract_unit %}disabled{% endif %}>
                                                        <option value="">---------</option>
                                                        {% for obj in unit_numbers %}
                                                            <option value="{{ obj.id }}"
                                                                    {% ifequal obj.id|stringformat:"s" request.GET.unit_number %}selected{% endifequal %}>{{ obj }}</option>
                                                        {% endfor %}
                                                    </select>
                                                </div>
                                            {% endifequal %}
                                            <input type="hidden" name="cont_id" value="{{ request.GET.cont_id }}">
                                            <input type="hidden" name="p" value="{{ request.GET.p }}">
                                            <input type="hidden" name="l" value="{{ request.GET.l }}">
                                            <input type="hidden" name="g" value="{{ request.GET.g }}">
                                            <input type="hidden" name="t" value="{{ request.GET.t }}">
                                            <input type="hidden" name="d" value="{{ request.GET.d }}">
                                            <input type="hidden" name="s" value="{{ request.GET.s }}">
                                            <input type="hidden" name="r" value="{{ request.GET.r }}">
                                            <input type="hidden" name="o" value="{{ request.GET.o }}">
                                            <input type="hidden" name="sd" value="{{ request.GET.sd }}">
                                            <input type="hidden" name="ed" value="{{ request.GET.ed }}">
                                            <input type="hidden" name="q" value="{{ request.GET.q }}">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

            <form method="post" name="form1" id="form1" class="col-12 needs-validation p-0" novalidate>
                {% csrf_token %}
                {{ form.project }}{{ form.project.errors }}
                {{ form.task }}{{ form.task.errors }}
                {{ form.order_group }}{{ form.order_group.errors }}
                {{ form.type }}{{ form.type.errors }}
                {{ form.contract_unit }}{{ form.contract_unit.errors }}
                {% ifequal this_project.is_unit_set True %}
                    {{ form.unit_number }}{{ form.unit_number.errors }}
                {% endifequal %}
                {{ form.back_url }}
                {{ form.errors }}
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="form-group mb-0 justify-content-end row  col-12">
                                    <div class="col-12">
                                        <div class="form-group col-12 row">
                                            {{ form.errors }}
                                            {% if request.GET.task == '1' or not request.GET.task %}
                                                <label for="{{ form.reservation_date.id_for_label }}"
                                                       class="col-4 col-md-2 col-lg-1 col-form-label">{{ form.reservation_date.label }}</label>
                                                <div class="col-8 col-md-4 col-lg-2">
                                                    {{ form.reservation_date|add_class:"form-control"|attr:"placeholder:청약일자"|attr:"data-provide=datepicker data-date-format=yyyy-mm-dd data-date-autoclose=true data-toggle=input-mask data-mask-format=0000-00-00" }}
                                                    {{ form.reservation_date.errors }}
                                                </div>
                                                <label for="{{ form.name.id_for_label }}"
                                                       class="col-4 col-md-2 col-lg-1 col-form-label">청약자명</label>
                                                <div class="col-8 col-md-4 col-lg-2">
                                                    {{ form.name|add_class:"form-control"|attr:"placeholder:청약자명" }}
                                                    {{ form.name.errors }}
                                                </div>
                                            {% elif request.GET.task == '2' %}
                                                <label for="{{ form.contract_date.id_for_label }}"
                                                       class="col-4 col-md-2 col-lg-1 col-form-label">{{ form.contract_date.label }}</label>
                                                <div class="col-8 col-md-4 col-lg-2">
                                                    {{ form.contract_date|add_class:"form-control"|attr:"placeholder:계약일자"|attr:"data-provide=datepicker data-date-format=yyyy-mm-dd data-date-autoclose=true data-toggle=input-mask data-mask-format=0000-00-00" }}
                                                    {{ form.contract_date.errors }}
                                                </div>
                                                <label for="{{ form.name.id_for_label }}"
                                                       class="col-4 col-md-2 col-lg-1 col-form-label">계약자명</label>
                                                <div class="col-8 col-md-4 col-lg-2">
                                                    {{ form.name|add_class:"form-control"|attr:"placeholder:계약자명" }}
                                                    {{ form.name.errors }}
                                                </div>
                                                <label for="{{ form.birth_date.id_for_label }}"
                                                       class="col-4 col-md-2 col-lg-1 col-form-label">{{ form.birth_date.label }}</label>
                                                <div class="col-8 col-md-4 col-lg-2">
                                                    {{ form.birth_date|add_class:"form-control"|attr:"placeholder:생년월일"|attr:"data-provide=datepicker data-date-format=yyyy-mm-dd data-date-autoclose=true data-toggle=input-mask data-mask-format=0000-00-00" }}
                                                    {{ form.birth_date.errors }}
                                                </div>
                                                <div class="col-md-6 col-lg-3 bg-dragula">
                                                    <div class="form-check col-12 pt-2">
                                                        {% for item in form.gender %}
                                                            {{ item }}
                                                        {% endfor %}
                                                        {{ form.gender.errors }}
                                                        <span class="ml-4">
                                                            {{ form.is_registed|add_class:"form-check-input input-sm" }}
                                                        <label for="{{ form.is_registed.id_for_label }}"
                                                               class="form-check-label">{{ form.is_registed.label }}</label>
                                                        </span>
                                                        {{ form.is_registed.errors }}
                                                    </div>
                                                </div>
                                            {% endif %}
                                        </div>

                                        <div class="form-group col-12 row">
                                            <label for="{{ form.cell_phone.id_for_label }}"
                                                   class="col-4 col-md-2 col-lg-1 col-form-label">{{ form.cell_phone.label }}</label>
                                            <div class="col-8 col-md-4 col-lg-2">
                                                {{ form.cell_phone|add_class:"form-control"|attr:"placeholder:휴대전화"|attr:"data-toggle=input-mask data-mask-format=000-0000-0000 data-reverse=true" }}
                                                {{ form.cell_phone.errors }}
                                            </div>

                                            <label for="{{ form.home_phone.id_for_label }}"
                                                   class="col-4 col-md-2 col-lg-1 col-form-label">{{ form.home_phone.label }}</label>
                                            <div class="col-8 col-md-4 col-lg-2">
                                                {{ form.home_phone|add_class:"form-control"|attr:"placeholder:집 전화"|attr:"data-toggle=input-mask data-mask-format=000-0000-0000 data-reverse=true" }}
                                                {{ form.home_phone.errors }}
                                            </div>

                                            <label for="{{ form.other_phone.id_for_label }}"
                                                   class="col-4 col-md-2 col-lg-1 col-form-label">{{ form.other_phone.label }}</label>
                                            <div class="col-8 col-md-4 col-lg-2">
                                                {{ form.other_phone|add_class:"form-control"|attr:"placeholder:기타전화"|attr:"data-toggle=input-mask data-mask-format=000-0000-0000 data-reverse=true" }}
                                                {{ form.other_phone.errors }}
                                            </div>

                                            <label for="{{ form.email.id_for_label }}"
                                                   class="col-4 col-md-2 col-lg-1 col-form-label">{{ form.email.label }}</label>
                                            <div class="col-8 col-md-4 col-lg-2">
                                                {{ form.email|add_class:"form-control"|attr:"placeholder:이메일" }}
                                                {{ form.email.errors }}
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                {# 계약금 인라인 폼셋 start #}
                                {{ formset.management_form }}

                                <fieldset class="empty-form" disabled style="display: none">
                                    <fieldset>
                                        <div class="form-row form-group mb-0 justify-content-end row pt-2 col-12 bg-light">
                                            <div class="col-12">
                                                <div class="form-group col-12 row">
                                                    <label class="col-4 col-md-2 col-lg-1 col-form-label">계약금
                                                        <i class="mdi mdi-plus-circle-outline font-18"></i></label>
                                                    <div class="col-8 col-md-3 col-lg-2">
                                                        <input type="text"
                                                               name="projectcashbook_set-__prefix__-deal_date"
                                                               id="id_projectcashbook_set-__prefix__-deal_date"
                                                               data-provide="datepicker" data-date-format="yyyy-mm-dd"
                                                               data-date-autoclose="true" data-toggle="input-mask"
                                                               data-mask-format="0000-00-00" placeholder="입금일"
                                                               class="form-control" maxlength="10" required>
                                                    </div>
                                                    <label class="d-md-none col-4 col-form-label">&nbsp;</label>
                                                    <div class="col-8 col-md-3 col-lg-2">
                                                        <input type="number"
                                                               name="projectcashbook_set-__prefix__-income"
                                                               min="0"
                                                               placeholder="입금액" class="form-control"
                                                               id="id_projectcashbook_set-__prefix__-income" required>
                                                    </div>
                                                    <label class="d-md-none col-4 col-form-label">&nbsp;</label>
                                                    <div class="col-8 col-md-3 col-lg-2">
                                                        <select name="projectcashbook_set-__prefix__-bank_account"
                                                                class="form-control"
                                                                id="id_projectcashbook_set-__prefix__-bank_account"
                                                                required>
                                                            <option value="" selected="">납부계좌선택</option>
                                                            {% for pb in project_bank_accounts %}
                                                                <option value="{{ pb.id }}">{{ pb }}</option>
                                                            {% endfor %}
                                                        </select>
                                                    </div>
                                                    <label class="d-lg-none col-4 col-md-2 col-form-label">&nbsp;</label>
                                                    <div class="col-8 col-md-3 col-lg-2">
                                                        <input type="text" name="projectcashbook_set-__prefix__-trader"
                                                               maxlength="30" placeholder="입금자성명" class="form-control"
                                                               id="id_projectcashbook_set-__prefix__-trader" required>
                                                    </div>
                                                    <label class="d-md-none col-4 col-form-label">&nbsp;</label>
                                                    <div class="col-8 col-md-3 col-lg-2">
                                                        <select name="projectcashbook_set-__prefix__-installment_order"
                                                                class="form-control"
                                                                id="id_projectcashbook_set-__prefix__-installment_order"
                                                                required>
                                                            <option value="" selected="">납부회차선택</option>
                                                            {% for io in installment_orders %}
                                                                <option value="{{ io.id }}">{{ io }}</option>
                                                            {% endfor %}
                                                        </select>
                                                    </div>
                                                    <div class="form-check col-5 col-md-3 col-lg-1 align-self-center">
                                                        <a href="javascript:void(0)" class="font-18"
                                                           style="color: #999">
                                                            <i class="mdi mdi-close-circle"
                                                               data-formset-remove-form></i>
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </fieldset>
                                </fieldset>

                                <fieldset class="forms col-12 p-0">
                                    {% for form in formset %}
                                        {% for hidden in form.hidden_fields %}
                                            {{ hidden }}
                                        {% endfor %}
                                        <fieldset>
                                            <div
                                                    class="form-row form-group mb-0 justify-content-end row pt-2 col-12 bg-light">
                                                <div class="col-12">
                                                    <div class="form-group col-12 row">
                                                        <label class="col-4 col-md-2 col-lg-1 col-form-label">계약금
                                                            [{{ forloop.counter }}]</label>
                                                        <div class="col-8 col-md-3 col-lg-2">
                                                            {{ form.deal_date|add_class:"form-control"|attr:"placeholder:입금일"|attr:"data-provide=datepicker data-date-format=yyyy-mm-dd data-date-autoclose=true data-toggle=input-mask data-mask-format=0000-00-00 required" }}
                                                            {{ form.deal_date.errors }}
                                                        </div>
                                                        <label class="d-md-none col-4 col-form-label">&nbsp;</label>
                                                        <div class="col-8 col-md-3 col-lg-2">
                                                            {{ form.income|add_class:"form-control"|attr:"placeholder:입금액"|attr:"required" }}
                                                            {{ form.income.errors }}
                                                        </div>
                                                        <label class="d-md-none col-4 col-form-label">&nbsp;</label>
                                                        <div class="col-8 col-md-3 col-lg-2">
                                                            {{ form.bank_account|add_class:"form-control"|attr:"required" }}
                                                            {{ form.bank_account.errors }}
                                                        </div>
                                                        <label class="d-lg-none col-4 col-md-2 col-form-label">&nbsp;</label>
                                                        <div class="col-8 col-md-3 col-lg-2">
                                                            {{ form.trader|add_class:"form-control"|attr:"placeholder:입금자성명"|attr:"required" }}
                                                            {{ form.trader.errors }}
                                                        </div>
                                                        <label class="d-md-none col-4 col-form-label">&nbsp;</label>
                                                        <div class="col-8 col-md-3 col-lg-2">
                                                            {{ form.installment_order|add_class:"form-control"|attr:"required" }}
                                                            {{ form.installment_order.errors }}
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </fieldset>
                                    {% endfor %}
                                </fieldset>

                                <fieldset
                                        class="controls form-row form-group mb-0 justify-content-end row pt-2 col-12 bg-light">
                                    <div class="col-11">
                                        <div class="form-group col-12 mt-0 row add-form-row justify-content-end">
                                            <a href="javascript:void(0)" data-formset-add-form>
                                                <i class="mdi mdi-plus-circle-outline text-info font-18"></i> 계약금 입금 내역
                                                추가하기
                                            </a>
                                        </div>
                                    </div>
                                </fieldset>
                                {# 계약금 인라인 폼셋 finish #}
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body pb-0">
                            <div class="row">
                                <div class="form-group mb-0 justify-content-end row  col-12">
                                    <div class="col-12">
                                        {% if request.GET.task == '2' %}
                                            <div class="form-group col-12 row">
                                                <div class="form-row col-12">
                                                    <label class="col-lg-1 col-form-label">{{ form.id_address1.label }}</label>
                                                    <div class="form-group col-8 col-md-4 col-lg-1">
                                                        {{ form.id_zipcode|add_class:"form-control"|attr:"placeholder:우편번호"|attr:"readonly"|attr:"onclick=sample2_execDaumPostcode('id_id_')" }}
                                                        {{ form.id_zipcode.errors }}
                                                    </div>

                                                    <div class="form-group col-4 col-md-6 col-lg-1">
                                                        <button type="button" class="btn btn-info"
                                                                onclick="sample2_execDaumPostcode('id_id_')">우편번호
                                                        </button>
                                                    </div>

                                                    <div class="form-group col-md-6 col-lg-4">
                                                        {{ form.id_address1|add_class:"form-control"|attr:"placeholder:주민등록 주소"|attr:"onclick=sample2_execDaumPostcode('id_id_')" }}
                                                        {{ form.id_address1.errors }}
                                                    </div>
                                                    <div class="form-group col-6 col-md-3 col-lg-2">
                                                        {{ form.id_address2|add_class:"form-control"|attr:"placeholder:상세주소" }}
                                                        {{ form.id_address2.errors }}
                                                    </div>
                                                    <div class="form-group col-6 col-md-3 col-lg-2">
                                                        {{ form.id_address3|add_class:"form-control"|attr:"placeholder:참고항목" }}
                                                        {{ form.id_address3.errors }}
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="form-group col-12 row">
                                                <div class="form-row col-12">
                                                    <label class="col-lg-1 col-form-label">{{ form.dm_address1.label }}</label>
                                                    <div class="form-group col-8 col-md-4 col-lg-1">
                                                        {{ form.dm_zipcode|add_class:"form-control"|attr:"placeholder:우편번호"|attr:"readonly"|attr:"onclick=sample2_execDaumPostcode('id_dm_')" }}
                                                        {{ form.dm_zipcode.errors }}
                                                    </div>
                                                    <div class="form-group col-4 col-md-6 col-lg-1">
                                                        <div class="">
                                                            <button type="button" class="btn btn-info"
                                                                    onclick="sample2_execDaumPostcode('id_dm_')">우편번호
                                                            </button>
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-md-6 col-lg-4">
                                                        {{ form.dm_address1|add_class:"form-control"|attr:"placeholder:우편송부 주소"|attr:"onclick=sample2_execDaumPostcode('id_dm_')" }}
                                                        {{ form.dm_address1.errors }}
                                                    </div>
                                                    <div class="form-grou col-6 col-md-3 col-lg-2">
                                                        {{ form.dm_address2|add_class:"form-control"|attr:"placeholder:상세주소" }}
                                                        {{ form.dm_address2.errors }}
                                                    </div>
                                                    <div class="form-group col-6 col-md-3 col-lg-2">
                                                        {{ form.dm_address3|add_class:"form-control"|attr:"placeholder:참고항목" }}
                                                        {{ form.dm_address3.errors }}
                                                    </div>
                                                    <div class="form-group form-check col-10 col-lg-1 pl-4 align-self-center">
                                                        <input class="form-check-input" type="checkbox" value=""
                                                               id="defaultCheck1" onclick="same_addr(this)">
                                                        <label class="form-check-label" for="defaultCheck1"
                                                               style="cursor: pointer;">상동</label>
                                                    </div>
                                                </div>
                                            </div>
                                        {% endif %}

                                        <div class="form-group col-12 row">
                                            <div class="form-row col-12">
                                                <label for="{{ form.note.id_for_label }}"
                                                       class="col-lg-1 col-form-label">{{ form.note.label }}</label>
                                                <div class="form-group col-lg-10">
                                                    {{ form.note|add_class:"form-control"|attr:"placeholder:비고"|attr:"rows:4" }}
                                                    {{ form.note.errors }}
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="form-group mb-0 justify-content-end row">
                                    <div class="col-12">
                                        {% if request.user.is_superuser or request.user.staffauth.contract > '1' %}
                                            {% if request.GET.contract_unit %}
                                                <button type="submit"
                                                        class="btn btn-{% if not request.GET.cont_id %}primary{% else %}success{% endif %}">등록하기</button>
                                            {% else %}
                                                <button type="button"
                                                        class="btn btn-{% if not request.GET.cont_id %}primary{% else %}success{% endif %}"
                                                            onclick="getValidatioin()">
                                                        등록하기
                                                </button>
                                            {% endif %}
                                        {% else %}
                                            <button type="button" class="btn btn-outline-secondary" onclick="alert('계약 등록 관리 권한이 없습니다. 관리자에게 문의하여 주십시요.')">조회권한 사용자</button>
                                        {% endif %}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div> <!-- container -->

{% endblock %}

{% block third_party_js %}

    <script>
      const form = document.project_form
      const order_group = document.getElementById('id_order_group')
      const type = document.getElementById('id_type')
      const contract_unit = document.getElementById('id_contract_unit')
      {% ifequal this_project.is_unit_set True %}
        const unit_number = document.getElementById('id_unit_number')
      {% endifequal %}
      const project = document.getElementById('id_project_sel')

      window.onload = function () {
        project.setAttribute('onchange', 'projectSelect()')
        {% if request.GET.cont_id %}
          project.disabled = true
        {% endif %}

        if ('{{ request.GET.task }}' == '1') {
          document.getElementById('id_reservation_date').required = true
        }

        if ('{{ request.GET.task }}' == '2') {
          document.getElementById('id_contract_date').required = true
          document.getElementById('id_birth_date').required = true
          document.getElementById('id_id_zipcode').required = true
          document.getElementById('id_id_address1').required = true
          document.getElementById('id_dm_zipcode').required = true
          document.getElementById('id_dm_address1').required = true
        }
      }

      function projectSelect() {
        const task = document.getElementById('id_task')
        const order_group = document.getElementById('id_order_group')
        const type = document.getElementById('id_type')
        const cont_unit = document.getElementById('id_contract_unit')

        {% ifequal this_project.is_unit_set True %}
          const unit_number = document.getElementById('id_unit_number')
          unit_number.options[0].selected = true
          unit_number.disabled = true
        {% endifequal %}

        cont_unit.options[0].selected = true
        cont_unit.disabled = true
        type.options[0].selected = true
        type.disabled = true
        order_group.options[0].selected = true
        order_group.disabled = true
        task.options[0].selected = true
        task.disabled = true

        form.submit()
      }

      function getSelect(obj, n) {
        if (obj.value === '') {
          switch (n) {
            case 1:
              order_group.options[0].selected = true
              type.options[0].selected = true
              contract_unit.options[0].selected = true
              order_group.disabled = true
              type.disabled = true
              contract_unit.disabled = true
            {% ifequal this_project.is_unit_set True %}
              unit_number.options[0].selected = true
              unit_number.disabled = true
            {% endifequal %}
              break
            case 2:
              type.options[0].selected = true
              contract_unit.options[0].selected = true
              type.disabled = true
              contract_unit.disabled = true
            {% ifequal this_project.is_unit_set True %}
              unit_number.options[0].selected = true
              unit_number.disabled = true
            {% endifequal %}
              break
            case 3:
              contract_unit.options[0].selected = true
              contract_unit.disabled = true
            {% ifequal this_project.is_unit_set True %}
              unit_number.options[0].selected = true
              unit_number.disabled = true
            {% endifequal %}
              break
              {% ifequal this_project.is_unit_set True %}
                case 4:
                  unit_number.options[0].selected = true
                  unit_number.disabled = true
                  break
              {% endifequal %}
          }
        } else {
          form.submit()
        }
      }

      function same_addr(chk) {
        var form = document.form1;

        if (chk.checked === true) {
          if (form.dm_zipcode.value || form.dm_address1.value || form.dm_address2.value || form.dm_address3.value) {
            if (confirm('주민등록 주소와 우편송부 주소가 서로 다릅니다.\n우편송부 주소를 주민등록 주소로 교체하시겠습니까?') === true) {
              form.dm_zipcode.value = form.id_zipcode.value
              form.dm_address1.value = form.id_address1.value
              form.dm_address2.value = form.id_address2.value
              form.dm_address3.value = form.id_address3.value
            } else {
              form.sa_addr.checked = false;
              return;
            }
          } else {
            form.dm_zipcode.value = form.id_zipcode.value
            form.dm_address1.value = form.id_address1.value
            form.dm_address2.value = form.id_address2.value
            form.dm_address3.value = form.id_address3.value
          }
        } else {
          form.dm_zipcode.value = null
          form.dm_address1.value = null
          form.dm_address2.value = null
          form.dm_address3.value = null
        }
      }

      function taskChange(val) {
        document.getElementById('task').value = val
      }

      function getValidatioin() {
        if ('{{ request.GET.task }}' == '' || '{{ request.GET.order_group }}' == '' || '{{ request.GET.type }}' == '' || '{{ request.GET.contract_unit }}' == '') {
          alert('등록할 유니트 정보(차수, 타입, 계약코드)를 모두 선택하여 주세요.')
        }
      }
    </script>

    <!-- formset add form script -->
    <script src="{% static 'common/js/formset_add_form.js' %}"></script>

    <!-- iOS에서는 position:fixed 버그가 있음, 적용하는 사이트에 맞게 position:absolute 등을 이용하여 top,left값 조정 필요 -->
    <div id="layer" style="display:none;position:fixed;overflow:hidden;z-index:1;-webkit-overflow-scrolling:touch;">
        <img src="//t1.daumcdn.net/postcode/resource/images/close.png" id="btnCloseLayer"
             style="cursor:pointer;position:absolute;right:-3px;top:-3px;z-index:1" onclick="closeDaumPostcode()"
             alt="닫기 버튼">
    </div>

    <script src="https://t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
    <script src="{% static 'common/js/daum_post_api.js' %}"></script>

{% endblock %}
